home *** CD-ROM | disk | FTP | other *** search
/ NetNews Offline 2 / NetNews Offline Volume 2.iso / news / comp / lang / c-part2 / 12575 < prev    next >
Encoding:
Text File  |  1996-08-05  |  1.2 KB  |  52 lines

  1. Path: in-news.erinet.com!usenet
  2. From: timb@erinet.com (Tim Berens)
  3. Newsgroups: comp.lang.c
  4. Subject: Re: Settle a bet please
  5. Date: Mon, 01 Apr 1996 22:37:36 GMT
  6. Organization: EriNet Online 513 436-9915
  7. Message-ID: <4jp8li$ue@eri2.erinet.com>
  8. References: <4jfopb$o9n@news1.sympatico.ca> <4jh8rtINNosd@mayne.ugrad.cs.ubc.ca>
  9. NNTP-Posting-Host: edlp177.erinet.com
  10. X-Newsreader: Forte Free Agent 1.0.82
  11.  
  12. c2a192@ugrad.cs.ubc.ca (Kazimir Kylheku) wrote:
  13.  
  14. >In article <4jfopb$o9n@news1.sympatico.ca>,
  15. >Gisele Swinson  <gisele.swinson@sympatico.ca> wrote:
  16. >>In C language, how do they calculate the length of an array.
  17. >>
  18. >>example
  19. >>
  20. >>To declare a string "My Name"
  21. >>
  22. >>is it char name[7] = "My Name"
  23. >>or
  24. >>is it chat Name[8] = "My Name"
  25. >>
  26. >>There is a battle in my class whether to include the NULL in the
  27. >>array size. 
  28.  
  29. >It's a null character, not the NULL pointer.
  30.  
  31. >>I would appreciate any input you might have.
  32.  
  33. >The proper way is to leave the size out unless you will be writing some other
  34. >string into the same field.
  35.  
  36. >char name[] = "My Name";
  37.  
  38. Here's an interesting way to decide for yourselves:
  39.  
  40. main()
  41. {
  42.     printf("size is: %d",sizeof("My Name"));
  43. }
  44.  
  45. This will display how many bytes your compiler thinks should be
  46. allocated for "My Name"
  47.  
  48. Tim
  49.  
  50.  
  51.  
  52.